<?php

/**
 * prepost PHP Class
 * Process Form Post Data
 */
 
class prepost
{

	private $data;
	private $firstname;
	private $lastname;
	private $email = null;
	private $phone = null;
	private $error = array();

	/**
	 * Summary of load
	 * @param mixed $data 
	 */
	public function load($data)
	{
		$this->data = $data;
	}

	/**
	 * Summary of errors
	 * @return mixed
	 */
	public function errors()
	{
		return $this->error;
	}
	
	/**
	 * Summary of vEmail
	 * @return mixed
	 */
	public function vEmail()
	{
		if(filter_var($this->data['email'], FILTER_VALIDATE_EMAIL))
		{
			$this->email = $this->data['email'];
			return true;
		} else {
			$this->error[] = "email";
		}
	}

    /**
     * Summary of vPhone
     * @return mixed
     */
    public function vPhone()
    {
		$rx_phone = '/^[+]?([\d]{0,3})?[\(\.\-\s]?([\d]{3})[\)\.\-\s]*([\d]{3})[\.\-\s]?([\d]{4})$/';
	
		if(preg_match($rx_phone, $this->data['phone']))
			{
				$this->phone = $this->data['phone'];
				return true;
			} else {
				$this->error[] = "phone";
			}
    }

     /**
      * Summary of vAlpha
      * @param mixed $str 
      * @return mixed
      */
     public function vAlpha($str)
     {
        if(ctype_alpha($this->data[$str]))
        {
			$this->$str = $this->data[$str];
        	return true;
        } else {
			$this->error[] = $str;
            return false;
    	}
	}

    /**
     * Summary of getPhone
     * @return mixed
     */
    public function getPhone()
    {
        return $this->phone;
    }

	/**
	 * Summary of getEmail
	 * @return mixed
	 */
	public function getEmail()
	{
		return $this->email;
	}
	
}

?>
